package com.yusheng.controller;

import com.yusheng.service.ApprovalUpdate;

import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.annotation.*;
import java.io.IOException;
import java.io.PrintWriter;

@WebServlet(name = "Aporoval", value = "/Aporoval")
public class Aporoval extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        //这里进行审批的servlet
        //1.获取参数
        request.setCharacterEncoding("utf-8");
        String opionion=request.getParameter("opionion");
        String  recordNo=request.getParameter("recordNo");
        String answer=request.getParameter("answer");

        //2.根据参数进行  审批处理业务，调用业务逻辑对象
        ApprovalUpdate approvalUpdate=new ApprovalUpdate();
        boolean success=approvalUpdate.processApproval(recordNo,answer,opionion);
        //3.把结果添加到响应体，返回
        response.setContentType("text/html;charset=utf-8");
        PrintWriter out=response.getWriter();
        if (success) out.print("<h1>更新成功，请前往审批页查询</h1>");
        else out.print("<h1>更新失败，重新审批</h1>");

    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

    }
}
